<?php

/**
 * 用户登录模块
 *
 * @since 1.0 2014-6-13 by sutroon
 */
class RegistionAction extends Action
{

    public function index()
    {
        layout(false);
        $this->display();
    }

    public function regist()
    {
        layout(false);
        $params = create_params();
        $useSession = C('SESSION_STATE');;
        if ($useSession) {
            $params->check_captcha(I('captcha'));
        }
        $params->addParam('userName', 'require', '用户名未填写');
        $params->addParam('password', 'require', '密码未填写');
        $params->confirm_param(I('password'), I('repassword'), '两次密码输入不一致');
        if ($params->hasError()) {
            $this->error($params->getError());
        }
        $params->removeParam('captcha');

        $userName = I('userName');
        $M = M('tuser');
        if ($M->where("userName='$userName'")->count('id') > 0) {
            $this->error('用户名已被注册!');
        }
        $result = $M->add($params->getParams());
        if (false !== $result) {
            $M->query("insert into tuser_appsetting (userID) values ($result);");
        }
        BaseAction::add_user_event_log('注册', "注册成功 [用户名:$userName]", true);
        $this->success('注册成功,请重新登录!', U('Login/index'));
    }

}
